<?php
include 'conf/tag_idioma.php';
  include 'conf/conexion_bd.php'; 
		  include 'funciones/funciones_imagenes.php';
		  include 'funciones/funciones_publicaciones.php';
		  include 'funciones/funciones_usuarios.php';
		  include 'funciones/funciones_preguntas.php';
		  include 'funciones/funciones_respuestas.php';
		  include 'funciones/funciones_ventas.php';
		  include 'funciones/funciones_queries.php';
		  include 'funciones/funciones_mail.php';
		  include 'funciones/funciones_categorias.php';
		  include 'funciones/funciones_estadisticas.php';
		  include 'funciones/funciones_ciudades.php';
		  include 'funciones/funciones_comentarios.php';
?>

<div class='span9'>


	<h3 class="h3borde">
		<?php echo gettext("Corriendo....");
		
		
		if (isset($_GET['accion'])){
		
			if($_GET['accion'] == 'delete'){
			
				eliminar_publicacion($_GET['id']);
				
				echo gettext("Publicacion Eliminada!");
			}
			
			if($_GET['accion'] == 'eliminarlinks'){
					
				eliminarLosLinksDeLasPublicacionesSEO();
			
				echo gettext("Links eliminados!");
			}
			
			if (($_GET['accion'] == 'extraermails')){
			
				$string = file_get_contents("mails.txt"); // Load text file contents
			
				// don't need to preassign $matches, it's created dynamically
			
				// this regex handles more email address formats like a+b@google.com.sg, and the i makes it case insensitive
				$pattern = '/[a-z0-9_\-\+]+@[a-z0-9\-]+\.([a-z]{2,3})(?:\.[a-z]{2})?/i';
			
				// preg_match_all returns an associative array
				preg_match_all($pattern, $string, $matches);
			
				// the data you want is in $matches[0], dump it with var_export() to see it
				var_export($matches[0]);
			
				foreach ($matches[0] as $mail){
					//echo $mail;					
						
					//$mails = explode(";",$mail);
						
					//foreach ($mails as $mailPosta){
						
					$sql = "DELETE FROM `newsletter_mails_clases_cursos` WHERE mail = '$mail';";					
					echo "$sql<br/>";
					$sql = "DELETE FROM `newsletter_mails_compra_venta` WHERE mail = '$mail';";
					echo "$sql<br/>";
					$sql = "DELETE FROM `newsletter_mails_empleos` WHERE mail = '$mail';";
					echo "$sql<br/>";
					$sql = "DELETE FROM `newsletter_mails_inmuebles` WHERE mail = '$mail';";
					echo "$sql<br/>";
					$sql = "DELETE FROM `newsletter_mails_servicios` WHERE mail = '$mail';";
					echo "$sql<br/>";
					$sql = "DELETE FROM `newsletter_mails_vehiculos` WHERE mail = '$mail';";
					echo "$sql<br/>";
					$sql = "DELETE FROM `newsletter_mails_turismo` WHERE mail = '$mail';";
					echo "$sql<br/>";
					
					
					//}
						
				}
			
				}
				if (($_GET['accion'] == 'extraermailswaha')){
						
					$string = file_get_contents("mails.txt"); // Load text file contents
						
					// don't need to preassign $matches, it's created dynamically
						
					// this regex handles more email address formats like a+b@google.com.sg, and the i makes it case insensitive
					$pattern = '/[a-z0-9_\-\+]+@[a-z0-9\-]+\.([a-z]{2,3})(?:\.[a-z]{2})?/i';
						
					// preg_match_all returns an associative array
					preg_match_all($pattern, $string, $matches);
						
					// the data you want is in $matches[0], dump it with var_export() to see it
					var_export($matches[0]);
						
					foreach ($matches[0] as $mail){
						//echo $mail;
				
						//$mails = explode(";",$mail);
				
						//foreach ($mails as $mailPosta){
						$mail = strtolower($mail);
				
						$sql = "DELETE FROM `newsletter_mails` WHERE mail = '$mail';";
						echo "$sql<br/>";			
							
							
						//}
				
					}
						
					}	
					if (($_GET['accion'] == 'nuevosmailsnews')){
					
						$string = file_get_contents("mails.txt"); // Load text file contents
					
						// don't need to preassign $matches, it's created dynamically
					
						// this regex handles more email address formats like a+b@google.com.sg, and the i makes it case insensitive
						$pattern = '/[a-z0-9_\-\+]+@[a-z0-9\-]+\.([a-z]{2,3})(?:\.[a-z]{2})?/i';
					
						// preg_match_all returns an associative array
						preg_match_all($pattern, $string, $matches);
					
						// the data you want is in $matches[0], dump it with var_export() to see it
						var_export($matches[0]);
					
						foreach ($matches[0] as $mail){
							//echo $mail;
					
							//$mails = explode(";",$mail);
					
							//foreach ($mails as $mailPosta){
							$mail = strtolower($mail);							
							$md5 = md5($mail);
							
							$sql = "REPLACE INTO `newsletter_mails`(`mail`, `md5`) VALUES ('$mail', '$md5');";
							echo "$sql<br/>";
								
								
							//}
					
						}
					
						}
			
			if($_GET['accion'] == 'mostrarmails'){
					
				$sql = "SELECT DISTINCT mail FROM usuarios";
				$result = mysql_query($sql);
			
				while ($usuario = mysql_fetch_array($result)){
					$mailN = strtolower($usuario['mail']);
					$md5 = md5($mailN);
					
					$sql = "REPLACE INTO `newsletter_mails`(`mail`, `md5`) VALUES ('$mailN', '$md5');";
					echo "$sql<br/>";
					
				}
			}
			if($_GET['accion'] == 'completarmailsnewsletters'){
					
				$sql = "SELECT * FROM usuarios";
				$result = mysql_query($sql);
					
				while ($usuario = mysql_fetch_array($result)){
					
					$mail = $usuario['mail'];
					$md5 = $usuario['token'];
					$ciudadId = $usuario['ciudad_id'];
					$username = $usuario['username'];
						
					mysql_query("INSERT INTO newsletter_mails_empleos (mail,md5,ciudad_id,username) VALUES ('$mail','.$md5.', ".$ciudadId.", '$username')");
					mysql_query("INSERT INTO newsletter_mails_inmuebles (mail,md5,ciudad_id,username) VALUES ('$mail','.$md5.', ".$ciudadId.", '$username')");
					mysql_query("INSERT INTO newsletter_mails_servicios (mail,md5,ciudad_id,username) VALUES ('$mail','.$md5.', ".$ciudadId.", '$username')");
					mysql_query("INSERT INTO newsletter_mails_turismo (mail,md5,ciudad_id,username) VALUES ('$mail','.$md5.', ".$ciudadId.", '$username')");
					mysql_query("INSERT INTO newsletter_mails_compra_venta (mail,md5,ciudad_id,username) VALUES ('$mail','.$md5.', ".$ciudadId.", '$username')");
					mysql_query("INSERT INTO newsletter_mails_clases_cursos (mail,md5,ciudad_id,username) VALUES ('$mail','.$md5.', ".$ciudadId.", '$username')");
					mysql_query("INSERT INTO newsletter_mails_vehiculos (mail,md5,ciudad_id,username) VALUES ('$mail','.$md5.', ".$ciudadId.", '$username')");
			
				}
			}


		}
		
		
		
		
		?>
	</h3>

	<?php 
	eliminarLosLinksDeLasPublicacionesSEO();
	?>
	<p>termino</p>
</div>

<div class='span3'></div>

<?php

?>